<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改游戏</title>
<%@ include file="/view/common/tags.jsp"%>
<link rel="stylesheet" href="${sysManagerV1}/js/kindeditor/themes/default/default.css" type="text/css"/>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateFrom" target="_parent"  enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-xs-2 text-right">游戏:</label>
				<div class="col-xs-3">
					<sk:select cssClass="form-control select" name="gameId" id="gameId" value="" requiredInit="true" ajaxURL="${userInfoV1}/baseGame/gameSelect?wm[DEL_FLAG]=1">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="gameName" id="gameName" value=""/>
				</div>
				<label class="col-xs-2 text-right">地图等级:</label>
				<div class="col-xs-3">
					<sk:select cssClass="form-control select" name="mapLevelId" id="mapLevelId" value="" requiredInit="true" ajaxURL="${userInfoV1}/gameMapLevel/select?wm[DEL_FLAG]=0">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="mapLevel" id="mapLevel" value=""/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">地图类型:</label>
				<div class="col-xs-3">
					<sk:select cssClass="form-control select" name="mapTypeId" id="mapTypeId" value="" requiredInit="true" ajaxURL="${userInfoV1}/gameMapType/select?wm[DEL_FLAG]=0">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="mapTypeName" id="mapTypeName" value=""/>
				</div>
				<label class="col-xs-2 text-right">地图名称:</label>
				<div class="col-xs-3">
					<input type="text" class="input" name="mapName" id="mapName" value="" placeholder="请输入地图名称" onblur="checkOperatorName();" style="width: 180px;">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-2 text-right">BOSS:</label>
				<div class="col-xs-3">
					<input type="text" class="input" name="boss" id="boss" value="" placeholder="BOSS" style="width: 180px;">
				</div>
				<label class="col-xs-2 text-right">怪物等级:</label>
				<div class="col-xs-3">
					<input type="text" class="input" name="freakLevel" id="freakLevel" value="" placeholder="怪物等级" style="width: 180px;">
				</div>
			</div>
            <div class="form-group" >
                <label class="col-xs-2 text-right">地图图片:</label>
                <div class="col-xs-9">
                <div class="cb_box cbx_img_bg">
                    <c:if test="${not empty tlzsGame.gameIcon}">
                        <img id="newmainImgPath" src="${pic}${tlzsGame.gameIcon}" width="160px;" height="118px;" onerror="javascript:this.src='${sysManagerV1}/images/uploadImage/noimage.gif';">
                    </c:if>
                    <c:if test="${empty tlzsGame.gameIcon}">
                        <img id="newmainImgPath" src="" width="160px;" height="118px;" onerror="javascript:this.src='${sysManagerV1}/images/uploadImage/noimage.gif';">
                    </c:if>
                    <div class="mainImgPathBox" style="margin-bottom: -56px;">
                        <a href="javascript:;" class="file">选择文件<input id="imgPath"  type="file" name="imgPath" onchange="newPic(this,'mainImgPath');"/>   </a>                    
                    </div>
                    <div class="exp_box" style="color:red;">建议尺寸为120*120px(jpg、bmp、png等)，并且小于500KB的图片。</div>
                </div>
                </div>
                <input type="hidden" id="mapImg" name="mapImg" value="${tlzsGame.gameIcon}">
            </div>
            <div class="form-group" >
                <label class="col-xs-2 text-right">是否发布:</label>
                <div class="col-xs-7">
                    <td colspan="2">
                        <label for="port"><input id="yse" name="fbFlag" type="radio" value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label for="no"><input id="no" name="fbFlag" type="radio" value="0"/>&nbsp;否</label>
                    </td>
                </div>
            </div>
			<div class="form-group">
				<label class="col-xs-2 text-right">排序编号:</label>
				<div class="col-xs-7">
					<input type="text" class="input" name="orderByNo" id="orderByNo" value="" placeholder="请输入排序编号">
				</div>
			</div>
            <!-- <div class="form-group" >
                <label class="col-xs-2 text-right">是否推荐:</label>
                <div class="col-xs-7">
                    <td colspan="2">
                        <label for="port"><input id="yse" name="tjFlag" type="radio" value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label for="no"><input id="no" name="tjFlag" type="radio" value="0"/>&nbsp;否</label>
                    </td>
                </div>
            </div> -->
            <div class="form-group" >
                <label class="col-xs-2 text-right">地图攻略:</label>
                <div class="col-xs-7">
                    <textarea id="mapRaider" name="mapRaider" style="width:470px;height:110px;border:#ccc solid 1px;text-indent:3px;padding-top:3px;"/>${tlzsGameStrategy.context}</textarea>
                </div>
            </div>
 			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
           	<input type="hidden" id="token" name="token" value="">
           	<input type="hidden" id="flag"  value="<%=request.getParameter("flag")%>">
           	<input type="hidden" id="isReCommit" value="0">
		</sk:form>	
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript" charset="UTF-8" src="${sysManagerV1}/js/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" charset="gbk" src="${sysManagerV1}/js/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript">

$(function(){
	$("#token").val(sessionStorage.getItem("token"));
	
	// 初始化
	KindEditor.ready(function(K) {
        ke = K.create("#mapRaider", {
            resizeType : 0,
            urlType : 'domain',
            uploadJson : '${sysManagerV1}/keUploadImg/uploadImg',
            items : [
             'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|',
             'quickformat', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor',  'hilitecolor', 'bold', 
             'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'link', 'unlink', 'image', 'emoticons', 'pagebreak', 
             '|', 'justifyleft', 'justifycenter', 
             'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'clearhtml', '|', 'preview', 'source', 'about' 
            ]
        });
    });
    
	var rowId = $("#rowId").val();
	if(rowId >= 0){
    	$.ajax({
            url: "${userInfoV1}/gameMaps/getInfo",
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#gameId").val(data.gameId);
                $("#gameName").val(data.gameName);
                $("#mapLevelId").val(data.mapLevelId);
                $("#mapLevel").val(data.mapLevel);
                $("#mapTypeId").val(data.mapTypeId);
                $("#mapTypeName").val(data.mapTypeName);
                $("#mapName").val(data.mapName);
                $("#boss").val(data.boss);
                $("#freakLevel").val(data.freakLevel);
                $("#orderByNo").val(data.orderByNo);
                if(data.mapImg != ""){
                    $("#newmainImgPath").attr("src", data.mapImg);
                } else {
                    $("#newmainImgPath").attr("src", "${sysManagerV1}/images/uploadImage/noimage.gif");
                }
                $("#mapImg").val(data.mapImg);
                if(data.fbFlag == 1){
                    $("#yse").attr("checked","true");
                    $("#no").removeAttr("checked");
                } else {
                    $("#yse").removeAttr("checked");
                    $("#no").attr("checked","true");
                }
                $("#mapRaider").val(data.mapRaider);
            }
        });
	}
})

var err = {'1':'添加','2':'修改'};
var action = {'1':'/save','2':'/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }
    var gameId = $.trim($("#gameId").val());
    if (!CheckUtil.isNotNull(gameId)) {
        layer.msg("请选择游戏!");
        return;
    }
    var gameName = $("#gameId").find("option:selected").text();
    $("#gameName").val(gameName);
    
    var mapLevelId = $.trim($("#mapLevelId").val());
    if (!CheckUtil.isNotNull(mapLevelId)) {
        layer.msg("请选择地图等级!");
        return;
    }
    var mapLevel = $("#mapLevelId").find("option:selected").text();
    $("#mapLevel").val(mapLevel);
    
    var mapTypeId = $.trim($("#mapTypeId").val());
    if (!CheckUtil.isNotNull(mapTypeId)) {
        layer.msg("请选择地图类型!");
        return;
    }
    var mapTypeName = $("#mapTypeId").find("option:selected").text();
    $("#mapTypeName").val(mapTypeName);
    
    var mapName = $.trim($("#mapName").val());
    $("#mapName").val(mapName);//渠道游戏ID去空格
    if (!CheckUtil.isNotNull(mapName)) {
        layer.msg("请输入地图名称!");
        return;
    }
    
    var gameIsExist = checkName();
    if (gameIsExist) {
        layer.msg("游戏地图名称重复");
        return false;
    }
    
    var boss = $.trim($("#boss").val());
    $("#boss").val(boss);//渠道游戏ID去空格
    if (!CheckUtil.isNotNull(boss)) {
        layer.msg("请输入BOSS!");
        return;
    }
    
    var freakLevel = $.trim($("#freakLevel").val());
    $("#freakLevel").val(freakLevel);//渠道游戏ID去空格
    if (!CheckUtil.isNotNull(freakLevel) || !CheckUtil.isInt(freakLevel, "+")) {
        layer.msg("请输入正确的怪物等级!");
        return;
    }
    
    var orderByNo = $('#orderByNo').val();
    if (!CheckUtil.isNotNull(orderByNo) || !CheckUtil.isInt(orderByNo, "+") || orderByNo == 0) {
        layer.msg("请输入正确的排序编号!");
        return;
    }
    var mapImg = $("#mapImg").val();//图片
    if (flag == 0) {//添加的时候
        if (!CheckUtil.isNotNull(mapImg)) {
            layer.msg("请选择所要上传的图片!");
            return;
        }
        if (CheckUtil.isNotNull(mapImg) && !CheckUtil.isImg(mapImg)) {
            layer.msg("上传文件只能为图片!");
            return ;
        }
    } else {
        if (CheckUtil.isNotNull(mapImg)) {
            if (!CheckUtil.isImg(mapImg)) {
                layer.msg("上传文件只能为图片!");
                return ;
            }
        }
    } 
    //富编辑框内容
    ke.sync();
    
    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    
    $.ajax({
        url: "${userInfoV1}/gameMaps" + action[i],
        type: "post",
        cache: false,
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
}

function checkName() {
	var gameId = $("#gameId").val();
	var mapLevelId = $("#mapLevelId").val();
	var mapTypeId = $("#mapTypeId").val();
    var mapName = $.trim($("#mapName").val());
    var rowId = $("#rowId").val();;
    var aa = false;
    if (CheckUtil.isNotNull(gameId) && CheckUtil.isNotNull(mapLevelId) && CheckUtil.isNotNull(mapTypeId) && CheckUtil.isNotNull(mapName)) {
        $.ajax({
            type: "post",
            cache: false,
            url: "${userInfoV1}/gameMaps/checkIsExist",
            data:{mapBigType:10, gameId:gameId, mapLevelId:mapLevelId, mapTypeId:mapTypeId, mapName:mapName, rowId:rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                aa = data;
            }
        });
    }
    return aa;  
}
</script>
</html>